import Vue from 'vue';
import Vuex from 'vuex';
import getters from "./getters";

import {Socket} from "../api/Socket";
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        socket: uni.getStorageSync('vuex').socket,
    },
    modules:{

    },
    getters,
    mutations: {
        SET_SOCKET(state, socket){
            if(socket) {
                state.socket = socket;
                uni.setStorageSync("socket", JSON.stringify(socket));
            }else{
                state.socket=JSON.parse(uni.getStorageSync('socket'))
                console.log(state.socket,"s")
            }
        },
        // 定义全局的清理方法
        REMOVE_SOCKET(state) {
            state.socket = '';
        },

    },
    actions: {
        SET_SOCKET({commit}, socket) {
            console.log("设置成功")
            commit('SET_SOCKET', socket)
        },
        REMOVE_SOCKET({commit}){
            commit("REMOVE_SOCKET")
        }
    },
})

